package demoMod.strongerheart;

import basemod.BaseMod;
import basemod.helpers.RelicType;
import basemod.interfaces.EditRelicsSubscriber;
import basemod.interfaces.EditStringsSubscriber;
import basemod.interfaces.StartGameSubscriber;
import com.badlogic.gdx.Gdx;
import com.evacipated.cardcrawl.modthespire.lib.SpireInitializer;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.*;
import demoMod.strongerheart.relics.StrongerHeartRelic;

import java.nio.charset.StandardCharsets;

@SpireInitializer
public class StrongerHeartMod implements EditStringsSubscriber,
        EditRelicsSubscriber,
        StartGameSubscriber {
    public static boolean enableReplace = true;

    public static String makeID(String name) {
        return "StrongerHeart:" + name;
    }

    public static String getResourcePath(String path) {
        return "StrongerHeartImages/" + path;
    }

    public static void initialize() {
        new StrongerHeartMod();
    }

    public StrongerHeartMod() {
        BaseMod.subscribe(this);
    }

    public static String getLanguageString() {
        String language;
        switch (Settings.language) {
            case ZHS:
                language = "zhs";
                break;
                /*
            case KOR:
                language = "kor";
                break;
            case JPN:
                language = "jpn";
                break;
                */
            default:
                language = "eng";
        }
        return language;
    }

    @Override
    public void receiveEditStrings() {
        String language;
        language = getLanguageString();

        String relicStrings = Gdx.files.internal("localization/" + language + "/StrongerHeart-RelicStrings.json").readString(String.valueOf(StandardCharsets.UTF_8));
        BaseMod.loadCustomStrings(RelicStrings.class, relicStrings);
        String powerStrings = Gdx.files.internal("localization/" + language + "/StrongerHeart-PowerStrings.json").readString(String.valueOf(StandardCharsets.UTF_8));
        BaseMod.loadCustomStrings(PowerStrings.class, powerStrings);
        String monsterStrings = Gdx.files.internal("localization/" + language + "/StrongerHeart-MonsterStrings.json").readString(String.valueOf(StandardCharsets.UTF_8));
        BaseMod.loadCustomStrings(MonsterStrings.class, monsterStrings);
    }

    @Override
    public void receiveEditRelics() {
        BaseMod.addRelic(new StrongerHeartRelic(), RelicType.SHARED);
    }

    @Override
    public void receiveStartGame() {
        if (!AbstractDungeon.player.hasRelic(StrongerHeartRelic.ID)) {
            new StrongerHeartRelic().instantObtain();
        }
    }
}
